//
//  MP_NetAPIManager.m
//  oc1
//
//  Created by kokuma on 2017/2/7.
//  Copyright © 2017年 kokumams. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MPNetAPIManager.h"

@implementation MPNetAPIManager

+ (MPNetAPIManager *)sharedManager {
    static MPNetAPIManager *shared_manager = nil;
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        shared_manager = [[self alloc] init];
    });
    return shared_manager;
}

- (void)login:(NSString *)mobile loginPwd:(NSString *)loginPwd andBlock:(void (^)(id data, NSError *error))block{
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/newAccounts/token" withParams:@{@"mobile" : mobile,@"loginPwd" : loginPwd} withMethodType:Post autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}

- (void)getRecommendUsers:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    // NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/follow/recom" withParams:@{@"page" : page,@"perPage" : @"28"} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
- (void)getUsersByKeyword:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    // NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/accounts/search" withParams:@{@"page" : page,@"perPage" : @"28",@"keyword" : @""} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
- (void)getAcgsByKeyword:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    // NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/acgs" withParams:@{@"page" : page,@"perPage" : @"28",@"keyword" : @""} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
- (void)getVenuesByKeyword:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    //  NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/venues" withParams:@{@"page" : page,@"perPage" : @"28",@"keyword" : @""} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
- (void)getTopicsByKeyword:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    //  NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/dynamic" withParams:@{@"page" : page,@"perPage" : @"28",@"keyword" : @"",@"positive" : @"4"} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
- (void)getCosWorksByKeyword:(NSString *)page andBlock:(void (^)(id data, NSError *error))block{
    //  NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:page, @"page", "8", @"perPage",nil];
    [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"/dynamic" withParams:@{@"page" : page,@"perPage" : @"28",@"keyword" : @"",@"positive" : @"1"} withMethodType:Get autoShowError:NO andBlock:^(id data, NSError *error) {
        if (data) {
            id resultData = [data valueForKeyPath:@"data"];
            block(resultData, nil);
        }else{
            block(nil, error);
        }
    }];
}
@end